首先,在Form中添加一个按钮和C1FlexGrid控件,并为按钮添加Click事件,添加以下逻辑:
1、得到C1Flexgrid中选中的单元格区域
C1.Win.C1FlexGrid.CellRange cr = this.c1FlexGrid1.Selection; 复制代码2、创建一个临时的C1Flexgrid对象
var fg = new C1.Win.C1FlexGrid.C1FlexGrid(); 复制代码3、根据选中单元格的范围,为临时的C1Flexgrid指定行列数
fg.Cols.Count = cr.c2 - cr.c1 + 1; fg.Cols.Fixed = 0; fg.Rows.Count = cr.r2 - cr.r1 + 1; fg.Rows.Fixed = 0; 复制代码4、给临时C1Flexgrid单元格赋值
for (int i = cr.r1; i <= cr.r2; i++) { for (int j = cr.c1; j <= cr.c2; j++) { fg[_row, _col] = this.c1FlexGrid1[i, j]; _col += 1; } _row += 1; _col = 0; } 复制代码5、对临时C1Flexgrid进行排序
fg.Sort(C1.Win.C1FlexGrid.SortFlags.Ascending, 0); 复制代码6、将临时C1Flexgrid中的值设置给原始的C1Flexgrid
for (int i = cr.r1; i <= cr.r2; i++) { for (int j = cr.c1; j <= cr.c2; j++) { this.c1FlexGrid1[i, j] = fg[_row, _col]; _col += 1; } _row += 1; _col = 0; } 复制代码运行效果截图:(64.38 K, 下载次数:10)